﻿using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NCT.INVPOS.DataAccessLayer.Entity;

namespace NCT.INVPOS.DataAccessLayer.Configurations
{
    public class ProductConfiguration : EntityTypeConfiguration<Product>
    {
        public ProductConfiguration()
        {
            HasKey(P => P.Id);

            Property(P => P.Name).IsRequired().HasMaxLength(30);
            Property(P => P.Code).IsRequired().HasMaxLength(30);

            Property(P => P.Cost).IsRequired();
            Property(P => P.Discount1).IsRequired();
            Property(P => P.Discount2).IsRequired();
            Property(P => P.Discount3).IsRequired();
            Property(P => P.Discount4).IsRequired();
            Property(P => P.Discount5).IsRequired();

            Property(P => P.ListPrice).IsRequired();
            Property(P => P.SalesPrice).IsRequired();

            Property(P => P.Model).IsOptional().HasMaxLength(30);
            Property(P => P.Description).IsOptional().HasMaxLength(100);

            HasOptional(P => P.Branch).WithMany(P => P.Products).HasForeignKey(P => P.BranchId);
            HasOptional(P => P.Category).WithMany(P => P.Products).HasForeignKey(P => P.CategoryId);
            HasOptional(P => P.Manufacturer).WithMany(P => P.Products).HasForeignKey(P => P.ManufacturerId);
            HasOptional(P => P.Supplier).WithMany(P => P.Products).HasForeignKey(P => P.SupplierId);
        }
    }
}
